package work.vcloud.baseinfo.controller;

import work.vcloud.frame.controller.BaseController;
import work.vcloud.frame.dao.OpenDao;
import work.vcloud.frame.vo.OutputVo;
import work.vcloud.frame.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.IOUtils;

import work.vcloud.baseinfo.vo.ExceptionVo;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@RestController
@Scope("prototype")
public class ClgcApiController extends BaseController {

	@Autowired
	OpenDao openDao;
	

    /**
     * 验证app
     */
	public void validateApp(Map<String, Object> map) throws Exception {
		map.put("sqlMapId", "app_api.AccessTokenDetail");
		Object tokenVo = openDao.queryForObject(map);
		if(tokenVo != null) {
			Map tokenMap = (Map) tokenVo;
			map.put("client_id", tokenMap.get("client_id"));
			map.put("sqlMapId", "api_deploy.selectPower");
			Integer result = (Integer) openDao.queryForObject(map);
			if (result <= 0) {
				   throw new ExceptionVo("4005","no authority");
			}
		}else{
            throw new ExceptionVo("4006","invalid access_token");
		}
	}
	
    /**
     * 验证token
     */
	public void validate(Map<String, Object> map) throws Exception {
		map.put("sqlMapId", "app_api.AccessTokenDetail");
		Object tokenVo = openDao.queryForObject(map);
		if(tokenVo != null) {
			Map tokenMap = (Map) tokenVo;
			map.put("client_id", tokenMap.get("client_id"));
			try {
				getParamList(map);
			} catch (Exception e) {
                throw new ExceptionVo("4005","no authority");
			}
		}else{
            throw new ExceptionVo("4006","invalid access_token");
		}
	}

	/**
	 * 获取接口参数
	 */
	public void getParamList(Map<String, Object> map) throws Exception {

		map.put("sqlMapId", "app_api.selectByName");

		Map result = (Map) openDao.queryForObject(map);
		if(null == result || null == result.get("aa_pk")) {
			throw new ExceptionVo("4005", "no authority");
		}else{
			result.put("sqlMapId", "app_api.paramsList");
			result.put("client_id", map.get("client_id"));
			List<Map<String, Object>> apiParams = openDao.queryForList(result);
			StringBuffer apiParamsSql = new StringBuffer();
			for (int i = 0; i < apiParams.size(); i++) {
				apiParamsSql.append(","+apiParams.get(i).get("param_column")+" \""+apiParams.get(i).get("param_name")+"\"");
			}
			//去掉第一个逗号
			if(!"".equals(apiParamsSql.toString())) {
				map.put("apiParamsSql", apiParamsSql.substring(1));
			}
		}

	}

    /**
     *  获取接口名称
     *
     */
	public String getApiName(String requestUri) {
        return requestUri.substring(requestUri.lastIndexOf("/")+1, requestUri.length());
    }
	
	/**
	 * 获取文章接口
	 *
	 */
	@RequestMapping("oAuth/api/getNewsData")
	public OutputVo getNewsData() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);

			PageVo page = readPage(request);
			if(null == page){
				page = new PageVo();
				page.setNumber(50); //默认为一次请求为50条数据
			}else{
				//一次最多返回500条数据
				if(page.getNumber() > 500){
					page.setNumber(500);
				}else if(page.getNumber() < 1){ //如数量设置错误则修改为默认值
					page.setNumber(50);
				}
			}

			Object currentPage = map.get("currentPage");
			Object number = map.get("number");
			if(null != currentPage){
				page.setCurrent(Integer.parseInt(currentPage.toString()));
			}
			if(null != number){
				page.setNumber(Integer.parseInt(number.toString()));
			}
			map.put("page", page);

			map.put("sqlMapId", "api_clgc.news");
			List<Map<String, Object>> dataList = openDao.queryForList(map);
			return output("0000", dataList, page);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}

	/**
	 * 获取德育点赞接口
	 *
	 */
	@RequestMapping("oAuth/api/getDydzData")
	public OutputVo getDydzData() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);

			PageVo page = readPage(request);
			if(null == page){
				page = new PageVo();
				page.setNumber(50); //默认为一次请求为50条数据
			}else{
				//一次最多返回500条数据
				if(page.getNumber() > 500){
					page.setNumber(500);
				}else if(page.getNumber() < 1){ //如数量设置错误则修改为默认值
					page.setNumber(50);
				}
			}

			Object currentPage = map.get("currentPage");
			Object number = map.get("number");
			if(null != currentPage){
				page.setCurrent(Integer.parseInt(currentPage.toString()));
			}
			if(null != number){
				page.setNumber(Integer.parseInt(number.toString()));
			}
			map.put("page", page);

			map.put("sqlMapId", "api_clgc.dydz");
			List<Map<String, Object>> dataList = openDao.queryForList(map);
			return output("0000", dataList, page);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}
	
	/**
	 * 获取微班刊接口
	 *
	 */
	@RequestMapping("oAuth/api/getWbkData")
	public OutputVo getWbkData() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);

			PageVo page = readPage(request);
			if(null == page){
				page = new PageVo();
				page.setNumber(50); //默认为一次请求为50条数据
			}else{
				//一次最多返回500条数据
				if(page.getNumber() > 500){
					page.setNumber(500);
				}else if(page.getNumber() < 1){ //如数量设置错误则修改为默认值
					page.setNumber(50);
				}
			}

			Object currentPage = map.get("currentPage");
			Object number = map.get("number");
			if(null != currentPage){
				page.setCurrent(Integer.parseInt(currentPage.toString()));
			}
			if(null != number){
				page.setNumber(Integer.parseInt(number.toString()));
			}
			map.put("page", page);

			map.put("sqlMapId", "api_clgc.wbk");
			List<Map<String, Object>> dataList = openDao.queryForList(map);
			return output("0000", dataList, page);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}
	
	//获取返回值
	public static List<Map<String, Object>> getReturnData(List<Map<String, Object>> dataList,String apiParamsSql) {
		
		List<String> paramList = new ArrayList<String>();
		String paramStr [] = apiParamsSql.split(",");
		for(int i=0; i<paramStr.length; i++) {
			paramList.add(paramStr[i].split(" ")[0]);
		}
		
		List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
		for(int i=0; i<dataList.size(); i++) {
			Map<String, Object> jsonData = JSONArray.parseObject(dataList.get(i).get("json_data").toString());
			Map<String, Object> tempMap = new HashMap<String, Object>();
			
			for(int j=0; j<paramList.size(); j++) {
				tempMap.put(paramList.get(j), jsonData.get((paramList.get(j))));
			}
			returnList.add(tempMap);
		}
		return returnList;
	}
	
	/**
	 * 获取部门信息
	 * @return
	 */
	@RequestMapping("oAuth/api/getClgcDepartmentData")
	public OutputVo getClgcDepartmentData() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);
			
			PageVo page = readPage(request);
			if(null == page){
				page = new PageVo();
				page.setNumber(50); //默认为一次请求为50条数据
			}else{
				//一次最多返回500条数据
				if(page.getNumber() > 500){
					page.setNumber(500);
				}else if(page.getNumber() < 1){ //如数量设置错误则修改为默认值
					page.setNumber(50);
				}
			}

			Object currentPage = map.get("currentPage");
			Object number = map.get("number");
			if(null != currentPage){
				page.setCurrent(Integer.parseInt(currentPage.toString()));
			}
			if(null != number){
				page.setNumber(Integer.parseInt(number.toString()));
			}
			map.put("page", page);
			
			map.put("sqlMapId", "api_datacenter.select");
			List<Map<String, Object>> dataList = openDao.queryForList(map);
	
			List<Map<String, Object>> returnList = getReturnData(dataList,map.get("apiParamsSql").toString());

			return output("0000", returnList,page);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}
	
	/**
	 * 获取班级课表信息接口
	 * @return
	 */
	@RequestMapping("oAuth/api/getClgcTimetableData")
	public OutputVo getClgcTimetableData() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);
			
			PageVo page = readPage(request);
			if(null == page){
				page = new PageVo();
				page.setNumber(50); //默认为一次请求为50条数据
			}else{
				//一次最多返回500条数据
				if(page.getNumber() > 500){
					page.setNumber(500);
				}else if(page.getNumber() < 1){ //如数量设置错误则修改为默认值
					page.setNumber(50);
				}
			}

			Object currentPage = map.get("currentPage");
			Object number = map.get("number");
			if(null != currentPage){
				page.setCurrent(Integer.parseInt(currentPage.toString()));
			}
			if(null != number){
				page.setNumber(Integer.parseInt(number.toString()));
			}
			map.put("page", page);
			
			map.put("sqlMapId", "api_datacenter.select");
			List<Map<String, Object>> dataList = openDao.queryForList(map);
	
			List<Map<String, Object>> returnList = getReturnData(dataList,map.get("apiParamsSql").toString());

			return output("0000", returnList,page);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}
	
	/**
	 * 获取课程信息接口
	 * @return
	 */
	@RequestMapping("oAuth/api/getClgcCourseData")
	public OutputVo getClgcCourseData() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);
			
			PageVo page = readPage(request);
			if(null == page){
				page = new PageVo();
				page.setNumber(50); //默认为一次请求为50条数据
			}else{
				//一次最多返回500条数据
				if(page.getNumber() > 500){
					page.setNumber(500);
				}else if(page.getNumber() < 1){ //如数量设置错误则修改为默认值
					page.setNumber(50);
				}
			}

			Object currentPage = map.get("currentPage");
			Object number = map.get("number");
			if(null != currentPage){
				page.setCurrent(Integer.parseInt(currentPage.toString()));
			}
			if(null != number){
				page.setNumber(Integer.parseInt(number.toString()));
			}
			map.put("page", page);
			
			map.put("sqlMapId", "api_datacenter.select");
			List<Map<String, Object>> dataList = openDao.queryForList(map);
	
			List<Map<String, Object>> returnList = getReturnData(dataList,map.get("apiParamsSql").toString());

			return output("0000", returnList,page);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		}  catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}
	
	/**
	 * 获取学生选课信息接口
	 * @return
	 */
	@RequestMapping("oAuth/api/getClgcCourseSelectData")
	public OutputVo getClgcCourseSelectData() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);
			
			PageVo page = readPage(request);
			if(null == page){
				page = new PageVo();
				page.setNumber(50); //默认为一次请求为50条数据
			}else{
				//一次最多返回500条数据
				if(page.getNumber() > 500){
					page.setNumber(500);
				}else if(page.getNumber() < 1){ //如数量设置错误则修改为默认值
					page.setNumber(50);
				}
			}

			Object currentPage = map.get("currentPage");
			Object number = map.get("number");
			if(null != currentPage){
				page.setCurrent(Integer.parseInt(currentPage.toString()));
			}
			if(null != number){
				page.setNumber(Integer.parseInt(number.toString()));
			}
			map.put("page", page);
			
			map.put("sqlMapId", "api_datacenter.select");
			List<Map<String, Object>> dataList = openDao.queryForList(map);
	
			List<Map<String, Object>> returnList = getReturnData(dataList,map.get("apiParamsSql").toString());

			return output("0000", returnList,page);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		}  catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}
	
	
	/**
	 * 获取教师排课信息接口
	 * @return
	 */
	@RequestMapping("oAuth/api/getClgcSchedulingData")
	public OutputVo getClgcSchedulingData() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);
			
			PageVo page = readPage(request);
			if(null == page){
				page = new PageVo();
				page.setNumber(50); //默认为一次请求为50条数据
			}else{
				//一次最多返回500条数据
				if(page.getNumber() > 500){
					page.setNumber(500);
				}else if(page.getNumber() < 1){ //如数量设置错误则修改为默认值
					page.setNumber(50);
				}
			}

			Object currentPage = map.get("currentPage");
			Object number = map.get("number");
			if(null != currentPage){
				page.setCurrent(Integer.parseInt(currentPage.toString()));
			}
			if(null != number){
				page.setNumber(Integer.parseInt(number.toString()));
			}
			map.put("page", page);
			
			map.put("sqlMapId", "api_datacenter.select");
			List<Map<String, Object>> dataList = openDao.queryForList(map);
	
			List<Map<String, Object>> returnList = getReturnData(dataList,map.get("apiParamsSql").toString());

			return output("0000", returnList,page);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		}  catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}
	
	/**
	 * 获取材料工程人员更新接口
	 * @return
	 */
	@RequestMapping("oAuth/api/getTeacherDataUpdate")
	public OutputVo getTeacherDataUpdate() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);
			
			PageVo page = readPage(request);
			if(null == page){
				page = new PageVo();
				page.setNumber(50); //默认为一次请求为50条数据
			}else{
				//一次最多返回500条数据
				if(page.getNumber() > 500){
					page.setNumber(500);
				}else if(page.getNumber() < 1){ //如数量设置错误则修改为默认值
					page.setNumber(50);
				}
			}

			Object currentPage = map.get("currentPage");
			Object number = map.get("number");
			if(null != currentPage){
				page.setCurrent(Integer.parseInt(currentPage.toString()));
			}
			if(null != number){
				page.setNumber(Integer.parseInt(number.toString()));
			}
			map.put("page", page);
			
			map.put("sqlMapId", "api_datacenter.select");
			List<Map<String, Object>> dataList = openDao.queryForList(map);
	
			List<Map<String, Object>> returnList = getReturnData(dataList,map.get("apiParamsSql").toString());

			return output("0000", returnList,page);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		}  catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}
	
	/**
	 * 获取材料工程部门信息更新接口
	 * @return
	 */
	@RequestMapping("oAuth/api/getDepartmentDataUpdate")
	public OutputVo getDepartmentDataUpdate() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);
			
			PageVo page = readPage(request);
			if(null == page){
				page = new PageVo();
				page.setNumber(50); //默认为一次请求为50条数据
			}else{
				//一次最多返回500条数据
				if(page.getNumber() > 500){
					page.setNumber(500);
				}else if(page.getNumber() < 1){ //如数量设置错误则修改为默认值
					page.setNumber(50);
				}
			}

			Object currentPage = map.get("currentPage");
			Object number = map.get("number");
			if(null != currentPage){
				page.setCurrent(Integer.parseInt(currentPage.toString()));
			}
			if(null != number){
				page.setNumber(Integer.parseInt(number.toString()));
			}
			map.put("page", page);
			
			map.put("sqlMapId", "api_datacenter.select");
			List<Map<String, Object>> dataList = openDao.queryForList(map);
	
			List<Map<String, Object>> returnList = getReturnData(dataList,map.get("apiParamsSql").toString());

			return output("0000", returnList,page);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		}  catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}
	
	/**
	 * 获取学生及所在专业信息接口
	 * @return
	 */
	@RequestMapping("oAuth/api/getClgcStudentData")
	public OutputVo getClgcStudentData() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);
			
			PageVo page = readPage(request);
			if(null == page){
				page = new PageVo();
				page.setNumber(50); //默认为一次请求为50条数据
			}else{
				//一次最多返回500条数据
				if(page.getNumber() > 500){
					page.setNumber(500);
				}else if(page.getNumber() < 1){ //如数量设置错误则修改为默认值
					page.setNumber(50);
				}
			}

			Object currentPage = map.get("currentPage");
			Object number = map.get("number");
			if(null != currentPage){
				page.setCurrent(Integer.parseInt(currentPage.toString()));
			}
			if(null != number){
				page.setNumber(Integer.parseInt(number.toString()));
			}
			map.put("page", page);
			
			map.put("sqlMapId", "api_datacenter.select");
			List<Map<String, Object>> dataList = openDao.queryForList(map);
	
			List<Map<String, Object>> returnList = getReturnData(dataList,map.get("apiParamsSql").toString());

			return output("0000", returnList,page);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}
	
	
	/**
	 * 获取专业信息接口
	 * @return
	 */
	@RequestMapping("oAuth/api/getClgcMajorData")
	public OutputVo getClgcMajorData() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);
			
			PageVo page = readPage(request);
			if(null == page){
				page = new PageVo();
				page.setNumber(50); //默认为一次请求为50条数据
			}else{
				//一次最多返回500条数据
				if(page.getNumber() > 500){
					page.setNumber(500);
				}else if(page.getNumber() < 1){ //如数量设置错误则修改为默认值
					page.setNumber(50);
				}
			}

			Object currentPage = map.get("currentPage");
			Object number = map.get("number");
			if(null != currentPage){
				page.setCurrent(Integer.parseInt(currentPage.toString()));
			}
			if(null != number){
				page.setNumber(Integer.parseInt(number.toString()));
			}
			map.put("page", page);
			
			map.put("sqlMapId", "api_datacenter.selectMajor");
			List<Map<String, Object>> dataList = openDao.queryForList(map);

			return output("0000", dataList,page);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}
	/*
	 * 连接clgc数据库
	 */
	public static Connection Conn() throws Exception{
		 Connection conn = null;
	      try {
	         Class.forName("org.postgresql.Driver");
	         conn = DriverManager.getConnection("jdbc:postgresql://192.168.1.235:5432/clgc","simpleframe", "CY2019!!");
	      } catch (Exception e) {
	    	  e.printStackTrace();
	      }
	      return conn;
	}
	
	
	/**
	 * 获取宿舍楼信息
	 * @return
	 */
	@RequestMapping("oAuth/api/getSSLYXX")
	public OutputVo getSSLYXX() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);
			

			Connection conn = Conn();
			
			String sql = "select "
			+'"'+"ID"+'"'+" as id,"
			+'"'+"DM"+'"'+" as dm,"
			+'"'+"MC"+'"'+" as mc,"
			+'"'+"CS"+'"'+" as cs,"
			+'"'+"XQ"+'"'+" as xqid,"
			+'"'+"DZ"+'"'+" as dz,"
			+'"'+"SYZT"+'"'+" as ztid,"
			+"(select name from clgcgms0710."+'"'+"PFW_T_DICT"+'"'+" where "+'"'+"ID"+'"'+" = "+'"'+"SYZT"+'"'+")  as ztname "
			+ "from clgcgms0710."+'"'+"T_XG_SSLYXX"+'"';
			
			PreparedStatement pst = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
			
			ResultSet rs = pst.executeQuery();
			
			ResultSetMetaData rsmd = null;
			rsmd = rs.getMetaData();
			
			List list = new ArrayList();
			
			int col =  rsmd.getColumnCount();
			
			while (rs.next()) {
				LinkedHashMap<Object, Object> lhm = new LinkedHashMap<>();
				for(int i=1; i<=col; i++) {
					lhm.put(rsmd.getColumnName(i),rs.getObject(i));
				}
				list.add(lhm);
			}
		
			return output(list);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}
	
	/**
	 * 获取宿舍楼信息
	 * @return
	 */
	@RequestMapping("oAuth/api/getSSXX")
	public OutputVo getSSXX() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);
			
			Connection conn = Conn();

			String sql = "select "
			+'"'+"ID"+'"'+" as id,"
			+'"'+"LYBID"+'"'+" as lyid,"
			+'"'+"SZLC"+'"'+" as szlc,"
			+'"'+"MC"+'"'+" as mc,"
			+'"'+"SSH"+'"'+" as ssh,"
			+'"'+"CPS"+'"'+" as cps,"
			+'"'+"CPH"+'"'+" as cph,"
			+"(case "+'"'+"ZSXB"+'"'+" when '1' then '男' else '女' end) as zsxb,"
			+"(case "+'"'+"SFYX"+'"'+" when '1' then '是' else '否' end) as sfyx "
			+ "from clgcgms0710."+'"'+"T_XG_SSXX"+'"';
			
			PreparedStatement pst = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
			
			ResultSet rs = pst.executeQuery();
			
			ResultSetMetaData rsmd = null;
			rsmd = rs.getMetaData();
			
			List list = new ArrayList();
			
			int col =  rsmd.getColumnCount();
			
			while (rs.next()) {
				LinkedHashMap<Object, Object> lhm = new LinkedHashMap<>();
				for(int i=1; i<=col; i++) {
					lhm.put(rsmd.getColumnName(i),rs.getObject(i));
				}
				list.add(lhm);
			}
		
			return output(list);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}
	
	/**
	 * 获取宿舍楼信息
	 * @return
	 */
	@RequestMapping("oAuth/api/getSSZSXXB")
	public OutputVo getSSZSXXB() {
		try {
			Map<String, Object> map = getParameterMap();

			map.put("api_name", getApiName(request.getRequestURI()));
			validate(map);
			

			Connection conn = Conn();
			
			String sql = "select "
			+'"'+"ID"+'"'+" as id,"
			+"(select "+'"'+"ST_XM"+'"'+" from clgcgms0710."+'"'+"T_JW_XSXX"+'"'+" where "+'"'+"ID"+'"'+" = sszsxxb."+'"'+"XSBID"+'"'+" ) as name,"
			+"(select "+'"'+"ST_XJH"+'"'+" from clgcgms0710."+'"'+"T_JW_XSXX"+'"'+" where "+'"'+"ID"+'"'+" = sszsxxb."+'"'+"XSBID"+'"'+" ) as xjh,"
			+"(select "+'"'+"ST_ZJHM"+'"'+" from clgcgms0710."+'"'+"T_JW_XSXX"+'"'+" where "+'"'+"ID"+'"'+" = sszsxxb."+'"'+"XSBID"+'"'+" ) as zjhm,"
			+"(select "+'"'+"ST_XH"+'"'+" from clgcgms0710."+'"'+"T_JW_XSXX"+'"'+" where "+'"'+"ID"+'"'+" = sszsxxb."+'"'+"XSBID"+'"'+" ) as xh,"
			+"(select "+'"'+"LYBID"+'"'+" from clgcgms0710."+'"'+"T_XG_SSXX"+'"'+" where "+'"'+"ID"+'"'+" = sszsxxb."+'"'+"SSBID"+'"'+") as lyid,"
			+'"'+"SSBID"+'"'+" as ssid,"
			+"(select"+'"'+"SSH"+'"'+" from clgcgms0710."+'"'+"T_XG_SSXX"+'"'+" where "+'"'+"ID"+'"'+" = sszsxxb."+'"'+"SSBID"+'"'+") as ssh,"	
			+'"'+"CPH"+'"'+" as cph,"
			+'"'+"RZRQ" +'"'+"as rzrq,"
			+'"'+"ZSZT"+'"'+ "as ztid,"
			+"(select name from clgcgms0710."+'"'+"PFW_T_DICT"+'"'+" where "+'"'+"ID"+'"'+" = "+'"'+"ZSZT"+'"'+") as ztname "
			+ "from clgcgms0710."+'"'+"T_XG_SSZSXXB"+'"'+" sszsxxb"
			+" where "+'"'+"ST_INPUT_TIME"+'"'+" like '2020%'";
			
			PreparedStatement pst = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
			
			ResultSet rs = pst.executeQuery();
			
			ResultSetMetaData rsmd = null;
			rsmd = rs.getMetaData();
			
			List list = new ArrayList();
			
			int col =  rsmd.getColumnCount();
			
			while (rs.next()) {
				LinkedHashMap<Object, Object> lhm = new LinkedHashMap<>();
				for(int i=1; i<=col; i++) {
					lhm.put(rsmd.getColumnName(i),rs.getObject(i));
				}
				list.add(lhm);
			}
		
			return output(list);
		} catch (ExceptionVo e) {
			return output(e.getCode(), e.getMsg(), "");
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999", "system exception", "");
		}
	}
}
